﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Univar.Helpers;

namespace Univar
{
	public class SessionStore : SessionStore<object>
	{
		public SessionStore(string key) : base(key) { }
		public SessionStore(string key, SessionIdentitySource scope) : base(key, scope) { }
	}

	public class SessionStore<T> : StoreBase<T, SessionStore<T>>
	{
		public SessionStore(string key) : base(key) { }
		public SessionStore(string key, SessionIdentitySource scope) : base(key, (Scopes)scope) { }

		protected override T GetValue(string key)
		{
			object value = Storage.Session.Get<object>(key, HttpContext);
			if (value == null)
				return DefaultValue;
			else
				return (T)value;
		}

		protected override void SetValue(string key, T value)
		{
			Storage.Session.Set<T>(key, value, HttpContext);
		}

		protected override object PlainValue
		{
			get { return Storage.Session.Get(Key); }
			set { Storage.Session.Set(Key, value); }
		}
	}

}
